#!/bin/sh
#
# Script args:
# $0: full path to script
# $1: full path to top level package dir, no trailing slash
# $2: full path to installed location
# $3:  ????? Path to install Volume????
# $4:  ?????

cp -f "$1/Contents/Resources/HUAWEI Mobile Connect - 3G Modem" "/System/Library/Modem Scripts/HUAWEI Mobile Connect - 3G Modem"

if sw_vers -productVersion |grep -c 10.5; then
cp -Rf "$1/Contents/Resources/HUAWEI Mobile.ccl" "/System/Library/Modem Scripts/"
fi

cp -f "$1/Contents/Resources/HUAWEI Mobile Connect - 3G Modem" "/Library/Modem Scripts/HUAWEI Mobile Connect - 3G Modem"

rm -Rf /System/Library/Extensions/HuaweiDataCardDriver.kext
mv -f /System/Library/HuaweiDataCardDriver.kext /System/Library/Extensions/HuaweiDataCardDriver.kext

rm -Rf /System/Library/Extensions/USBExpressCardCantWake_Huawei.kext
mv -f /System/Library/USBExpressCardCantWake_Huawei.kext /System/Library/Extensions/USBExpressCardCantWake_Huawei.kext

chown -R root:wheel /System/Library/Extensions/HuaweiDataCardDriver.kext
chmod -R 755 /System/Library/Extensions/HuaweiDataCardDriver.kext

chown -R root:wheel /System/Library/Extensions/USBExpressCardCantWake_Huawei.kext
chmod -R 755 /System/Library/Extensions/USBExpressCardCantWake_Huawei.kext

rm /System/Library/Extensions.kextcache
kextcache -k /System/Library/Extensions
rm -Rf /System/Library/Caches
touch /System/Library/Extensions

kextload -t /System/Library/Extensions/HuaweiDataCardDriver.kext/Contents/PlugIns/*.kext
PID=`ps -axc | grep kextd | perl -e '($a,$r,$z)=split /  */, <>; print $r;'`
kill -HUP $PID

if ls /dev/tty.* |grep -c HUAWEIMobile-Pcui;then
    #cp /System/Library/HuaweiDataCardDriver.kext /System/HuaweiDataCardDriver.kext
	ls
else
	if kextstat|grep AppleUSBCDC;then
        kextunload /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBCDC.kext
        /System/Library/Extensions/HuaweiDataCardDriver.kext/Contents/PlugIns/HWActivateApp
        kextload /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBCDC.kext
    else
        /System/Library/Extensions/HuaweiDataCardDriver.kext/Contents/PlugIns/HWActivateApp
    fi

    if sw_vers -productVersion |grep -c 10.4; then
        if kextstat|grep AppleUSBCDCDMM.kext;then
            kextunload /System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBCDCDMM.kext
        fi
    fi
fi

if sw_vers -productVersion |grep -c 10.5; then
#kextcache -k /System/Library/Extensions
touch /System/Library/Extensions
fi
if sw_vers -productVersion |grep -c 10.6; then
touch /System/Library/Extensions
fi

exit 0
